package com.aaa.service.impl;

import com.aaa.entity.TBook;
import com.aaa.dao.TBookDao;
import com.aaa.service.TBookService;
import org.springframework.stereotype.Service;


import javax.annotation.Resource;
import java.util.List;

/**
 * (TBook)表服务实现类
 *
 * @author makejava
 * @since 2023-06-02 16:07:48
 */
@Service("tBookService")
public class TBookServiceImpl implements TBookService {
    @Resource
    private TBookDao tBookDao;

    /**
     * 通过ID查询单条数据
     *
     * @param bookId 主键
     * @return 实例对象
     */
    @Override
    public TBook queryById(Integer bookId) {
        return this.tBookDao.queryById(bookId);
    }



    /**
     * 新增数据
     *
     * @param tBook 实例对象
     * @return 实例对象
     */
    @Override
    public TBook insert(TBook tBook) {
        this.tBookDao.insert(tBook);
        return tBook;
    }

    /**
     * 修改数据
     *
     * @param tBook 实例对象
     * @return 实例对象
     */
    @Override
    public TBook update(TBook tBook) {
        this.tBookDao.update(tBook);
        return this.queryById(tBook.getBookId());
    }

    /**
     * 通过主键删除数据
     *
     * @param bookId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer bookId) {
        return this.tBookDao.deleteById(bookId) > 0;
    }

    @Override
    public List<TBook> queryAll() {
        return this.tBookDao.queryAll();
    }

    @Override
    public long getCount() {
        TBook book = new TBook();
        return this.tBookDao.count(book);
    }
}
